from fastapi import APIRouter
from ..utils.post_item import PanelImageItem
import os
from .. import loop
from ..utils.chart import panel_data_by_period_task, failure_data_by_period_task, panel_pixel_heatmap_task, chip_pixel_heatmap_task


router = APIRouter()

root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# 柱状图
@router.post('/panel-data-by-period')
async def panel_data_by_period(item: PanelImageItem):
    end_time = item.end_time 
    start_time = item.start_time
    material_names = item.material_names
    server_hosts = item.server_hosts
    period_type = item.period_type
    static = item.static

    res = await loop.run_in_executor(None, panel_data_by_period_task, period_type, start_time, static)

    return res


@router.post('/failure-data-by-period')
async def failure_data_by_period(item: PanelImageItem):
    end_time = item.end_time 
    start_time = item.start_time
    material_names = item.material_names
    server_hosts = item.server_hosts
    period_type = item.period_type

    # res = failure_data_by_period_task(period_type, start_time)

    res = await loop.run_in_executor(None, failure_data_by_period_task, period_type, start_time)

    return res
    

# 所有 panel 图片上的使用 矩形框 绘制检测点F
@router.post('/panel-pixel-heatmap')
async def panel_pixel_heatmap(item: PanelImageItem):
    period_type = item.period_type
    start_time = item.start_time
    top_3 = item.top_3

    res = await loop.run_in_executor(None, panel_pixel_heatmap_task, period_type, start_time, top_3)

    return res


# 所有 panel 图片上的使用 矩形框 绘制检测点F
@router.post('/chip-pixel-heatmap')
async def panel_pixel_heatmap(item: PanelImageItem):
    period_type = item.period_type
    start_time = item.start_time
    chip_type = item.chip_type

    res = await loop.run_in_executor(None, chip_pixel_heatmap_task, chip_type, period_type, start_time)

    return res